package com.ftqh.tutorial.security.entity;

import com.ftqh.tutorial.security.data.AbstractDomain;
import lombok.*;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.security.core.GrantedAuthority;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Table;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2016/12/27
 * \* Time: 14:08
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
@Entity
@Table(name = "sys_security_role")
@EntityListeners(AuditingEntityListener.class)
@Data
@EqualsAndHashCode(callSuper=true)
@ToString(exclude={"description"})
@NoArgsConstructor
public class Role extends AbstractDomain<Integer> implements GrantedAuthority {

    private static final long serialVersionUID = -4313663960983962035L;
    @Column(nullable = false)
    private String name;
    private String description;

    @Override
    public String getAuthority() {
        return name;
    }

    public Role(int id, String name){
        this.setId(id);
        this.setName(name);
    }
}
